const express = require("express");

const server = express();

// 接收json格式数据
server.use(express.json());
server.post("/address", (req, res) => {
    console.log(req.body);

    res.end("/address");
})

// 接收普通键值对数据
server.use(express.urlencoded());

server.post("/address/concat", (req, res) => {
    console.log(req.body);
    res.end("/address/concat");
})

// 接收 formdata 格式数据，上传文件
const multer = require("multer");
// 上传的文件会保存在这个目录下
const upload = multer({
    dest: 'uploads/'
})

server.post("/address/formdata", upload.single('cover'), (req, res) => {
    console.log(req.body);
    console.log(req.file);
    res.end("/address/formdata");
})

server.listen(8001, () => {
    console.log('ok');
})